/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.alerts;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author ben
 */
@Entity
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "AlertGroup.findAll", query = "SELECT b FROM AlertGroup b"),
    @NamedQuery(name = "AlertGroup.findById", query = "SELECT b FROM AlertGroup b WHERE b.id = :alertGroupId")})  
public class AlertGroup implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;
    
    //An Alert Group can have many comments to it
    @OneToMany(mappedBy = "alertGroup", fetch = FetchType.LAZY)
    private List<Comment> comments;

    public List<Comment> getComments() {
        return comments;
    }

    public void setComments(List<Comment> comments) {
        this.comments = comments;
    }
    
    
    
    // Mapping back to Alert: An Alert Group can
    // have many Alerts
    @OneToMany(mappedBy = "alertGroup", fetch = FetchType.LAZY)
    private List<Alert> alerts;
    
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof AlertGroup)) {
            return false;
        }
        AlertGroup other = (AlertGroup) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
       return "AlertGroup{" + "id=" + id + ", comments=" + comments + ", alerts=" + alerts + '}';
    //return null;
    }

    

    public List<Alert> getAlerts() {
        return alerts;
    }

    public void setAlerts(List<Alert> alerts) {
        this.alerts = alerts;
    }
    
    
    
}
